package org.huzhp.gateway.core;

import com.netflix.eureka.util.StatusInfo;

/**
 * @Description: 注册中心状态类
 * @Author: huzp
 * @CreateDate: 2020/3/16 22:44
 * @Version: 1.0
 */
public class GatewayStatus {
    private String name;

    private String version;

    private String url;

    private String numOfCpus;

    private String totalAvailMemory;

    private String currentMemoryUsage;

    private String serverUptime;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getNumOfCpus() {
        return numOfCpus;
    }

    public void setNumOfCpus(String numOfCpus) {
        this.numOfCpus = numOfCpus;
    }

    public String getTotalAvailMemory() {
        return totalAvailMemory;
    }

    public void setTotalAvailMemory(String totalAvailMemory) {
        this.totalAvailMemory = totalAvailMemory;
    }

    public String getCurrentMemoryUsage() {
        return currentMemoryUsage;
    }

    public void setCurrentMemoryUsage(String currentMemoryUsage) {
        this.currentMemoryUsage = currentMemoryUsage;
    }

    public String getServerUptime() {
        return serverUptime;
    }

    public void setServerUptime(String serverUptime) {
        this.serverUptime = serverUptime;
    }

    public GatewayStatus() {
        Runtime runtime = Runtime.getRuntime();
        int totalMem = (int) (runtime.totalMemory() / 1048576L);
        int freeMem = (int) (runtime.freeMemory() / 1048576L);
        int usedPercent = (int) ((double) (((float) totalMem - (float) freeMem) / (float) totalMem) * 100.0D);
        this.numOfCpus = String.valueOf(runtime.availableProcessors());
        this.totalAvailMemory = totalMem + "mb";
        this.currentMemoryUsage = totalMem - freeMem + "mb (" + usedPercent + "%)";
        this.serverUptime = StatusInfo.getUpTime();
    }


}
